﻿using PioneerBoilerplate.Service.Admin.Permission.Input;
using PioneerBoilerplate.Service.Admin.Permission.Output;
using AutoMapper;
using System.Linq;
using PioneerBoilerplate.Model.Admin;

namespace PioneerBoilerplate.Service.Admin.Permission
{
    /// <summary>
    /// 映射配置
    /// </summary>
    public class MapConfig : Profile
    {
        public MapConfig()
        {
            CreateMap<PermissionAddGroupInput, PermissionEntity>();
            CreateMap<PermissionAddMenuInput, PermissionEntity>();
            CreateMap<PermissionAddApiInput, PermissionEntity>();
            CreateMap<PermissionAddDotInput, PermissionEntity>();
            
            CreateMap<PermissionUpdateGroupInput, PermissionEntity>();
            CreateMap<PermissionUpdateMenuInput, PermissionEntity>();
            CreateMap<PermissionUpdateApiInput, PermissionEntity>();
            CreateMap<PermissionUpdateDotInput, PermissionEntity>();

            CreateMap<PermissionEntity, PermissionGetDotOutput>().ForMember(
                d => d.ApiIds,
                m => m.MapFrom(s => s.PermissionApis.Select(a => a.ApiId))
            );

            CreateMap<PermissionEntity, PermissionGetGroupOutput>();
            CreateMap<PermissionEntity, PermissionGetMenuOutput>();
            CreateMap<PermissionEntity, PermissionGetApiOutput>();

            CreateMap<PermissionEntity, PermissionListOutput>();
            
        }
    }
}